﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;

using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace Weazel.Math.Test
{
  [TestClass]
  public class TestSignedAddition
  {
    /**************************************************************************
		 * Addition (Signed)
		 **************************************************************************/
    [TestMethod]
    public void TestSignedAddition_1()
    {
      Integer a = new Integer(8, 0, true);
      Integer b = new Integer(8, 0, true);
      Assert.AreEqual("0", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_2()
    {
      Integer a = new Integer(8, 1, true);
      Integer b = new Integer(8, 0, true);
      Assert.AreEqual("1", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_3()
    {
      Integer a = new Integer(8, 10, true);
      Integer b = new Integer(8, 100, true);
      Assert.AreEqual("110", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_4()
    {
      Integer a = new Integer(8, -1, true);
      Integer b = new Integer(8, 0, true);
      Assert.AreEqual("-1", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_5()
    {
      Integer a = new Integer(8, -100, true);
      Integer b = new Integer(8, -10, true);
      Assert.AreEqual("-110", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_6()
    {
      Integer a = new Integer(32, "0xFFFFFFFF", true);
      Integer b = new Integer(2, 1, true);
      Assert.AreEqual("0", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_7()
    {
      Integer a = new Integer(32, "0x7FFFFFFF", true);
      Integer b = new Integer(8, -0xF, true);
      Assert.AreEqual("7ffffff0", (a + b).ToHexadecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_8()
    {
      Integer a = new Integer(64, "0xFFFFFFFFFFFFFFFF", true);
      Integer b = new Integer(8, "0xFF", true);
      Assert.AreEqual("-2", (a + b).ToDecimalString());
    }

    [TestMethod]
    public void TestSignedAddition_9()
    {
      Integer a = new Integer(64, "0xFFFFFFFFFFFFFFFF", true);
      Integer b = new Integer(8, "0xFF", true);
      Integer r = new Integer(32, true);
      Integer.Add(ref r, a, b);
      Assert.AreEqual("-2", r.ToDecimalString());
    }
  }
}
